import http from '@/shouyun/request/index'

const state = {
	config: {}, // APP配置信息
}

const getters = {
	initConfig: state => state.config,
}

const actions = {
	// 初始化数据
	async appInit({
		commit,
		dispatch
	}, options) {
		let result = {}
		const customerResult = await http('customer.customerConfig')
		if (customerResult.code === 1) {
			result = {...customerResult.data}
		}
		const projectResult = await http('project.itemConfig')
		if (projectResult.code === 1) {
			result = {...result, ...projectResult.data}
		}
		commit('config', result)
		return result
	},
}

const mutations = {
	config(state, data) {
		state.config = data
		uni.setStorageSync("config", data)
	},
}

export default {
	state,
	mutations,
	actions,
	getters
}
